package com.bigdata.schaduler.domain;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;

import java.util.ArrayList;
import java.util.List;

/**
 * 不需要processDefinitionCode、processDefinitionVersion
 * create、update接口里面，会使用ProcessDefinition自动赋值
 */
@Data
public class TaskRelationParam {
  private String name;
  private Long projectCode;

  /**
   * 前置任务，没有则为 0
   */
  private Long preTaskCode;
  /**
   * 前置任务版本，没有则为0
   */
  private int preTaskVersion;

  private Long postTaskCode;
  private int postTaskVersion;

  public void setTaskRelationParam(ProcessTaskRelation processTaskRelation) {
    BeanUtil.copyProperties(processTaskRelation, this);
  }

  public List<TaskRelationParam> setTaskRelationParamList(List<ProcessTaskRelation> processTaskRelationList) {
    List<TaskRelationParam> relationParamList = new ArrayList<>();
    processTaskRelationList.forEach(processTaskRelation -> {
      TaskRelationParam relationParam = new TaskRelationParam();
      BeanUtil.copyProperties(processTaskRelation, relationParam);
      relationParamList.add(relationParam);
    });
    return relationParamList;
  }
}
